package com.learn.Controller;

import com.learn.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/03/20
 * @description 测试Thymeleaf控制器
 */
@Controller
public class ThymeleafController {
    @GetMapping({"/", "/index"})
    public String index(@RequestParam(value = "username", required = false) String username, Model model) {
        model.addAttribute("username", username);
        model.addAttribute("htmlCode", "<hr>");
        model.addAttribute("url", "https://cn.bing.com");
        model.addAttribute("styles", "color:red");
        model.addAttribute("display", "true");
        model.addAttribute("imgUrl", "/learn1.png");
        model.addAttribute("gender", "1");
        return "index";
    }
    @GetMapping("/list")
    public String list(Model model) {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            users.add(new User("user" + i, i, i%2));
        }
        model.addAttribute("users", users);
        return "list";
    }
}
